package com.threadLocal;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by huangyugen on 2019/05/14
 **/
public class DateUtil {

    private static final ThreadLocal<DateFormat> df = new ThreadLocal<DateFormat>(){
        @Override
        protected DateFormat initialValue() {
            return new SimpleDateFormat("yyyy-MM-dd");
        }
    };

    public static String format(Date date){
        return df.get().format(date);
    }

    public static void main(String[] args) {
        System.out.println(DateUtil.format(new Date()));
    }
}
